package com.boot.dog.common.enums;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: MaxLv
 * @Date: 2019/12/2
 */
@Getter
@AllArgsConstructor
public enum UserType implements EnumConst {

    INTERNAL("1", "内部用户"),

    GOVERNMENT("2", "监管用户"),

    ENTERPRISE("3", "企业用户"),

    SUPER_ADMIN("99999", "超级管理员");

    private final String code;
    private final String text;

    @Override
    public String code() {
        return this.code;
    }

    @Override
    public String text() {
        return this.text;
    }

    private static final Map<String, String> codeMap = new HashMap<>();

    static {
        for (UserType item : values()) {
            codeMap.put(item.code(), item.text());
        }
    }

    @Override
    public boolean isValid(String code) {
        if (StrUtil.isEmpty(code)) {
            return false;
        }
        return codeMap.containsKey(code);
    }

    public static String getText(String code) {
        if (codeMap.containsKey(code)) {
            return codeMap.get(code);
        }
        return StrUtil.EMPTY;
    }
}
